package com.glory.wxelectricitypda.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.wxelectricitypda.R;
import com.glory.wxelectricitypda.bean.FTTestSetUpQueryBean;

import java.util.List;

public class FTTestSetUpQueryAdapter extends BaseQuickAdapter<FTTestSetUpQueryBean.TestProgDTO, BaseViewHolder> {

    private int position = -1;

    public FTTestSetUpQueryAdapter(@Nullable List<FTTestSetUpQueryBean.TestProgDTO> data) {
        super(R.layout.adapter_ft_test_progress,data);
    }


    @Override
    protected void convert(BaseViewHolder helper, FTTestSetUpQueryBean.TestProgDTO item) {

        helper.setText(R.id.step,String.valueOf(item.getSTEP()));
        helper.setText(R.id.testType,item.getTEST_TYPE());
        helper.setText(R.id.testErrupt,item.getTESTERRUPT());
        CheckBox checkbox = helper.getView(R.id.checkbox);
        switch (item.getTEST_STATUS()){
            case "0":
                helper.setText(R.id.testStatus,"未开始");
                checkbox.setEnabled(true);
                break;
            case "1":
                helper.setText(R.id.testStatus,"测试中");
                checkbox.setEnabled(true);
                break;
            case "2":
                helper.setText(R.id.testStatus,"已采集");
                checkbox.setEnabled(false);
                break;
        }

        checkbox.setTag(helper.getAdapterPosition());
        checkbox.setChecked(helper.getAdapterPosition() == position);
        checkbox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean isChecked = ((CheckBox) v).isChecked();
                if (isChecked) {
                    int adapterPosition = helper.getAdapterPosition();
                    if (adapterPosition == position) {
                        return;
                    }

                    position = adapterPosition;
                    notifyDataSetChanged();
                } else {
                    position = -1;
                }
            }
        });

    }

    public int getPosition() {
        return this.position;
    }

}
